package com.lagou.edu.user.service.impl;

import com.lagou.edu.common.pojo.Token;
import com.lagou.edu.user.dao.ITokenRepository;
import com.lagou.edu.user.service.ITokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.UUID;

/**
 * created by kirito at 2020/7/13
 */
@Service
public class TokenServiceImpl implements ITokenService {

    @Autowired
    private ITokenRepository tokenRepository;

    @Override
    public String createToken() {
        return UUID.randomUUID().toString();
    }

    @Override
    public void saveToken(String email, String token) {
        Token t = new Token();
        t.setEmail(email);
        t.setToken(token);
        tokenRepository.save(t);
    }

    @Override
    public String getEmail(String token) {
        return tokenRepository.findByToken(token).getEmail();
    }
}
